package com.hh.bss.project.dao.impl;

import static com.hh.bss.util.ObjectUtils.isNotEmpty;

import java.util.ArrayList;
import java.util.List;

import com.hh.bss.base.BaseHibernateDao;
import com.hh.bss.common.MapObjectRowMapper;
import com.hh.bss.common.page.Page;
import com.hh.bss.project.dao.AccountPnAttachmentDao;
import com.hh.bss.project.entity.AccountPnAttachment;
import com.hh.bss.project.vo.query.AccountPnAttachmentQuery;
import com.hh.bss.talent.vo.query.CvAttachmentQuery;
import com.hh.bss.util.DateHelper;
import com.hh.bss.util.StringHelper;

public class AccountPnAttachmentDaoImpl extends BaseHibernateDao<AccountPnAttachment, Integer> implements AccountPnAttachmentDao<AccountPnAttachment, Integer> {

	@Override
	public Class getEntityClass() {
		return AccountPnAttachment.class;
	}
	@Override
	public Page findPage(AccountPnAttachmentQuery query) {
		    Class[] os={AccountPnAttachmentQuery.class};
    		Class property= org.springframework.beans.BeanUtils.findPropertyType(query.getField_type(), os);
        if (property!=null){
        	 if ("java.lang.String".equals(property.getName())){
	    			
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(),query.getQuery());
	    			
	    		}
	    		else if ("java.lang.Integer".equals(property.getName())){
	    			
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), StringHelper.parseInteger(query.getQuery(), 0));
	    			
	    		}
	    		else if ("java.lang.Double".equals(property.getName())){
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), StringHelper.parseDouble(query.getQuery(), 0));
	    		}
	    		else if ("java.util.Date".equals(property.getName())){
	    			com.hh.bss.util.BeanUtils.setProperty(query, query.getField_type(), DateHelper.toDate(query.getQuery(), DateHelper.DEFAULT_DATE_FORMAT));
	    		}
        }	 
        
        StringBuffer sql = new StringBuffer();
		List values = new ArrayList();
		sql.append(" select * from ( ");
		sql.append(" select a.id,a.pn_id pnId,a.name,a.file_name fileName,file_size fileSize,creator,create_dt createDt  from account_pn_attachment a  where 1=1 ");
		sql.append(" ) pnatt ");
		sql.append(" where 1=1 ");
		if(isNotEmpty(query.getPnId())){
			sql.append(" and pnatt.pnId = ?  ");
			values.add(query.getPnId());
		}
		return super.getJdbcDao().createPage(sql.toString(),values.toArray(), new MapObjectRowMapper(), query.getPageSize(), query.getPageNumber());
	}

	

}
